<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="反馈标题" prop="feedbackTitle">
        <el-input
          v-model="queryParams.feedbackTitle"
          placeholder="请输入反馈标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回复状态" prop="replyStatus">
        <el-select
          v-model="queryParams.replyStatus"
          placeholder="请选择回复状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_advice_reply_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否公开" prop="isPublic">
        <el-select
          v-model="queryParams.isPublic"
          placeholder="请选择是否公开"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_advice_is_public"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['advice:info:edit']"
          >修改回复</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['advice:info:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="infoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="序号"
        type="index"
        :index="table_index"
        width="50"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="反馈者"
        align="center"
        prop="feedbackName"
        width="100"
      />
      <el-table-column
        label="反馈标题"
        align="center"
        prop="feedbackTitle"
        width="100"
      />
      <el-table-column
        label="反馈时间"
        align="center"
        prop="feedbackTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.feedbackTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="回复者"
        align="center"
        prop="replyName"
        width="100"
      />
      <el-table-column
        label="回复时间"
        align="center"
        prop="replyTime"
        width="100"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.replyTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="回复状态"
        align="center"
        prop="replyStatus"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_advice_reply_status"
            :value="scope.row.replyStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="是否公开"
        align="center"
        prop="isPublic"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_advice_is_public"
            :value="scope.row.isPublic"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.replyStatus != 1"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['advice:info:edit']"
            >回复</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleContent(scope.row)"
            >查看内容
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['advice:info:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--查看建言回复内容-->
    <el-dialog
      :title="title"
      :visible.sync="openContent"
      width="780px"
      align="center"
      append-to-body
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col>
            <el-card>
              <el-form-item label="反馈内容" prop="feedbackContent">
                <div>
                  {{ form.feedbackContent }}
                </div>
              </el-form-item>
            </el-card>
          </el-col>
        </el-row>
        <el-row>
          <el-card>
            <el-col>
              <el-form-item label="回复内容" prop="adviceContent">
                <div v-html="form.replyContent"></div>
              </el-form-item>
            </el-col>
          </el-card>
        </el-row>
        <el-row>
          <el-col>
            <!-- <image-preview :src="form.feedbackPhoto" /> -->
            <el-card>
              <div class="block" v-if="srcListTrue">
                <span class="demonstration">反馈图片</span>
                <el-carousel
                  :autoplay="false"
                  indicator-position="outside"
                  height="300px"
                >
                  <el-carousel-item v-for="item in srcList" :key="item">
                    <image-preview :src="item" />
                  </el-carousel-item>
                </el-carousel>
              </div>
              <div v-else align="center">占无图片</div>
            </el-card>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 添加或修改反馈(校长邮箱)对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="780px"
      align="center"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公开状态">
              <el-radio-group v-model="form.isPublic">
                <el-radio
                  v-for="dict in dict.type.sys_advice_is_public"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="回复内容">
              <editor v-model="form.replyContent" :min-height="192" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInfo,
  getInfo,
  delInfo,
  addInfo,
  updateInfo,
} from "@/api/advice/info";

export default {
  name: "Info",
  dicts: ["sys_advice_reply_status", "sys_advice_is_public"],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 反馈(校长邮箱)表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //查看内容弹出层
      openContent: false,
      //图片路径
      url: "",
      //图片路径集合
      srcList: [],
      srcListTrue: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        feedbackTitle: undefined,
        replyStatus: undefined,
        isPublic: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        replyContent: [
          { required: true, message: "回复内容不能为空", trigger: "blur" },
        ],
        isPublic: [
          { required: true, message: "是否公开不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //序号换页问题
    table_index(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 查询反馈(校长邮箱)列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then((response) => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        feedbackId: undefined,
        feedbackTitle: undefined,
        feedbackContent: undefined,
        feedbackPhoto: undefined,
        feedbackTime: undefined,
        replyId: undefined,
        replyStatus: "0",
        replyContent: undefined,
        isPublic: "0",
        replyTime: undefined,
        remark: undefined,
        isDelete: undefined,
        deleteBy: undefined,
        deleteTime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getInfo(id).then((response) => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "回复";
      });
    },
    /** 查询公告内容按钮操作 */
    handleContent(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getInfo(id).then((response) => {
        this.loading = false;
        this.form = response.data;
        if (this.form.feedbackPhoto != null) {
          this.srcListTrue = true;
          this.srcList = this.form.feedbackPhoto.split(",");
        } else {
          this.srcListTrue = false;
        }

        this.openContent = true;
        this.title = row.feedbackTitle;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateInfo(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addInfo(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除反馈(校长邮箱)编号为"' + ids + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delInfo(ids);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },

  },
};
</script>
<style scoped>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.tabletitle-timeline {
  line-height: 18px !important;
}
.el-card.is-always-shadow {
  margin: 20px;
}
.el-dialog__header {
  text-align: center;
}
.span {
  margin-top: 2% !important;
  margin-left: 48% !important;
}
.title {
  text-align: center;
  display: block;
  font-weight: bold;
}
</style>
